//
//  MyVoiceView.swift
//  imprint
//
//  Created by 小柠檬🍋 on 2025/1/16.
//

import SwiftUI

//系统音色
struct SystemVoiceView: View {
    //用父试图来管理数据
    @ObservedObject var viewModel : SystemVoiceViewModel
    var choose = false
    let onChoose: (AiVoiceBean) -> Void

    var body: some View {
        if !viewModel.status.isEmpty {
            HomeEmptyView(text1: viewModel.status)
        } else {
            ScrollView {
                // 数据列表
                ForEach(viewModel.items) { item in
                    SystemVoiceItemView(item: item,choose: choose) { aiVoiceBean in
                        onChoose(aiVoiceBean)
                    }
                }
                
                LoadMoreFooter(refreshing: $viewModel.footerRefreshing, action: {
                    viewModel.getData(false)
                }) {
                    LoadMoreView(noMore: viewModel.noMore, footerRefreshing: viewModel.footerRefreshing)
                }
                .noMore(viewModel.noMore)
                .preload(offset: 10)
            }
            .enableRefresh()
            .onAppear{
                if !viewModel.isInit {
                    viewModel.getData(true)
                    viewModel.isInit = true
                }
            }
        }
    }
}

#Preview {
    SystemVoiceView(viewModel: SystemVoiceViewModel()) { _ in}
}
